let swi = document.querySelectorAll('.signIn_interface');
let cont = document.querySelectorAll('.content');
let kuai = document.querySelector('.kuai');
let reg_btn = document.querySelector('.register_btn');

// register.onclick = function(){
// 	kuai.style.left = '224px';
// }
let flag = true;
$('.passwordSwitch').click(function(){
	if(flag){
		$('#register_password').attr('type','text');
		$('.passwordSwitch').css('background','url(./images/guan.png)')
		$('.passwordSwitch').css('background-size','100% 100%')
	}else{
		$('#register_password').attr('type','password');
		$('.passwordSwitch').css('background','url(./images/kai.png)')
		$('.passwordSwitch').css('background-size','100% 100%')
	}
	flag = !flag;
})
let flag2 = true;
$('.passwordSwitch2').click(function(){
	if(flag2){
		$('#user_password').attr('type','text');
		$('.passwordSwitch2').css('background','url(./images/guan.png)')
		$('.passwordSwitch2').css('background-size','100% 100%')
	}else{
		$('#user_password').attr('type','password');
		$('.passwordSwitch2').css('background','url(./images/kai.png)')
		$('.passwordSwitch2').css('background-size','100% 100%')
	}
	flag2 = !flag2;
})
for(let i=0; i<swi.length; i++){
	swi[i].onclick = function(){
		for(let j=0; j<swi.length; j++){
			swi[j].classList.remove('active');
			cont[j].classList.remove('show');
		}
		swi[i].classList.add('active');
		cont[i].classList.add('show');
	}
}

reg_btn.onclick = function(){
	$.ajax({
		url: 'http://chonghekj.com/todo/index.php/Home/User/reg',
		type: 'post',
		dataType: 'json',
		data: {
			user_name: $('#register_name').val(),
			user_password: $('#register_password').val(),
			user_email: $('#register_mailbox').val()
		},
		success: function(res){
			alert('注册成功');
			$('#register_name').val('');
			$('#register_password').val('');
			$('#register_mailbox').val('');
			// console.log(res);
		}
	})
}
$('#register_name').blur(function(){
	$.ajax({
		url: 'http://chonghekj.com/todo/index.php/Home/User/checkUserName',
		type: 'post',
		dataType: 'json',
		data: {
			user_name: $('#register_name').val()
		},
		success: function(res){
			// console.log(res)
			if(res.info == '用户名重复'){
				$('.repeatPrompt').css('display','block');
				// alert('用户名重复');
			}
		}
	})
})
$('#register_name').focus(function(){
	$('.repeatPrompt').css('display','none');
})
$('.signIn_btn').click(function(){
	$.ajax({
		url: 'http://chonghekj.com/todo/index.php/Home/User/login',
		type: 'post',
		dataType: 'json',
		data: {
			user_name: $('#user_name').val(),
			user_password: $('#user_password').val()
		},
		success: function(res){
			if(res.info == '登录成功'){
				// console.log(res);
				localStorage.setItem('userinfo',JSON.stringify(res.data));
				location.href = `content.html`;
			}else{
				$('.errorPrompt').css('display','block')
			}
		}
	})
})
$('#user_name').focus(function(){
	$('.errorPrompt').css('display','none')
})
$('#user_password').focus(function(){
	$('.errorPrompt').css('display','none')
})